-
Notifications
You must be signed in to change notification settings - Fork 158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix double initialisation of variables in ASR #1629
Conversation
|
||
if( init_expr && current_body) { | ||
if( init_expr && current_body && | ||
(is_runtime_expression || !is_variable_const)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only those variables will be initialised by converting to assignments which are non-constant or have a runtime expressions. Also an error is thrown if a constant variable is not initialised at declaration (see lines 2215 to 2219).
src/libasr/asr_verify.cpp
Outdated
@@ -516,6 +516,15 @@ class VerifyVisitor : public BaseWalkVisitor<VerifyVisitor> | |||
"Variable::m_parent_symtab must be present in the ASR (" | |||
+ std::string(x.m_name) + ")"); | |||
|
|||
if( symtab->parent == nullptr ) { | |||
// For nowRestrict this check only to variables which are present |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// For nowRestrict this check only to variables which are present | |
// For now restrict this check only to variables which are present |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this is good, thanks for fixing it and adding a test!
I suggest we merge it, and if there are more issues, we'll tackle it as we discover it.
Okay. Let me check if verify changes work with LFortran. Then I will merge both the PRs. |
1. Only those variables which are constant and have a compile time initialisation expression will have non-nullptr values for m_symbolic_value and m_value 2. Rest all will be converted to assignment statements.
Closes #1626